package org.elanfox.cloud.mybatis.ddl.model;

import lombok.Data;
import org.elanfox.cloud.mybatis.ddl.dos.SchemaColumn;

/**
 * @author allan
 * @version 1.0.0
 * @date 2021/4/20
 */
@Data
public class EntityColumn {
    private String name;
    private String jdbcType;
    private String dataType;
    private boolean nullable;
    private boolean unique;
    private String comment;
    /**
     * 是否为主键
     */
    private boolean key;
    private boolean autoIncrement;

    public boolean isEqualsToSchemaColumn(SchemaColumn column) {
        if (
                this.name.equalsIgnoreCase(column.getColumn_name()) &&
                        this.dataType.equalsIgnoreCase(column.getData_type()) &&
                        this.unique == column.isUnique() &&
                        this.nullable == column.isNullable() &&
                        this.key == column.isPrimaryKey()
        ) {
            if (this.autoIncrement) {
                return "auto_increment".equalsIgnoreCase(column.getExtra());
            } else {
                return !"auto_increment".equalsIgnoreCase(column.getExtra());
            }
        }
        return false;
    }
}
